package com.ali.gts.servlet.service.impl;

import com.ali.gts.servlet.dao.BookDao;
import com.ali.gts.servlet.dao.UserDao;
import com.ali.gts.servlet.dao.impl.BookDaoImpl;
import com.ali.gts.servlet.dao.impl.UserDaoImpl;
import com.ali.gts.servlet.domain.Book;
import com.ali.gts.servlet.domain.User;
import com.ali.gts.servlet.service.ThreadLocalService;

import java.math.BigDecimal;
import java.util.UUID;

public class ThreadLocalServiceImpl implements ThreadLocalService {

    private UserDao userDao = new UserDaoImpl();

    private BookDao bookDao = new BookDaoImpl();

    @Override
    public void threadLocalTransaction() {
        String id = UUID.randomUUID().toString();//生成一个36位的随机值作为id
        User user = new User();
        user.setId(id);
        user.setUsername("gaoshusen");
        user.setEmail("123@122.com");
        user.setPassword("2309292");
        userDao.insert(user);
        Book book = new Book(1222,"java1","gaohq", BigDecimal.valueOf(23.01),20,20,"");
        bookDao.addBook(book);


        int i = 3 / 0;
        System.out.println("===事务执行完了");

    }
}
